home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet multimedia / Grafika i zdjecia / Edytory grafiki rastrowej i wektorowej / Inscape 0.44.1 / Inkscape-0.44.1-1.win32.exe / share / extensions / extractimage.py < prev    next >
Text File  |  2006-09-06  |  2KB  |  51 lines

  1. #!/usr/bin/env python 
  2. '''
  3. Copyright (C) 2005 Aaron Spike, aaron@ekips.org
  4.  
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9.  
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18. '''
  19.  
  20. import inkex, base64
  21.  
  22. class MyEffect(inkex.Effect):
  23.     def __init__(self):
  24.         inkex.Effect.__init__(self)
  25.         self.OptionParser.add_option("--filepath",
  26.                         action="store", type="string", 
  27.                         dest="filepath", default=None,
  28.                         help="")
  29.     def effect(self):
  30.         ctx = inkex.xml.xpath.Context.Context(self.document,processorNss=inkex.NSS)
  31.         
  32.         # exbed the first embedded image
  33.         path = self.options.filepath
  34.         if (path != ''):
  35.             if (self.options.ids):
  36.                 for id, node in self.selected.iteritems():
  37.                     if node.tagName == 'image':
  38.                         xlink = node.attributes.getNamedItemNS(inkex.NSS[u'xlink'],'href')
  39.                         if (xlink.value[:4]=='data'):
  40.                             comma = xlink.value.find(',')
  41.                             if comma>0:
  42.                                 data = base64.decodestring(xlink.value[comma:])
  43.                                 open(path,'wb').write(data)
  44.                                 xlink.value = path
  45.                             else:
  46.                                 inkex.debug('Difficulty finding the image data.')
  47.                             break
  48.  
  49. e = MyEffect()
  50. e.affect()
  51.